package com.hxjy.struts2.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hxjy.dao.EmployeeDao;
import com.hxjy.entity.Employee;
import com.hxjy.page.Pager;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 员工控制层
 * 主要功能：
 * 负责-----
 * @author 李彬
 *
 */
@Controller
@Scope("prototype")
public class EmployeeAction extends ActionSupport {
	private static Log log = LogFactory.getLog(EmployeeAction.class);
	private EmployeeDao employeeDao;
//	private GroupDao groupDao;
//	private CompanyDao companyDao;
//	private CollieryDao collieryDao;
//	private DepartmentDao departmentDao;
//	private RoleDao roleDao;
//	private List<Group> groupList;
//	private List<Company> companyList;
//	private List<Colliery> collieryList;
//	private List<Department> departmentList;
//	private List<Role> roleList;
	private List<Employee> employeeList;
	private Employee employee;
	private int count;
	private Pager pager;
	
	/**
	 * 获取员工列表
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:44:03 AM
	 */
	public String employeeQuery() {
		int offset = pager==null?0:pager.getOffset();
		Object[] objs = employeeDao.getEmployeeList(employee,offset);
		employeeList = (List<Employee>) objs[0];
		count = Integer.parseInt(objs[1].toString());
		return "employeeQueryPage";
	}
	/**
	 * 跳转到添加页面
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:44:59 AM
	 */
	public String toEmployeeAddPage(){
//		departmentList=departmentDao.getDepartmentList();
		//groupList=groupDao.getGroupList();
		return "employeeAddPage";
	}
	/**
	 * 添加员工
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:55:35 AM
	 */
	public String doAddEmployee(){
		employeeDao.saveEmployee(employee);
		return "employeeQueryAction";
	}
	/**
	 * 跳转到修改页面
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:45:18 AM
	 */
	public String toEmployeeEditPage(){
		employee = employeeDao.getEmployeeById(employee.getId());
	//	groupList=groupDao.getGroupList();
		return "employeeEditPage";
	}
	/**
	 * 修改员工
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:56:24 AM
	 */
	public String doEditEmployee(){
		employeeDao.updateEmployee(employee);
		return "employeeQueryAction";
	}
	/**
	 * 删除员工
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20138:46:24 AM
	 */
	public String employeeDel(){
		employeeDao.deleteEmployee(employee.getId());
		return "employeeQueryAction";
	}
	/**
	 * 详情页面
	 * 方法描述:
	 * 创建人:李彬
	 * 创建时间：Apr 2, 20136:19:57 PM
	 */
	public String employeeDetail(){
		employee = employeeDao.getEmployeeById(employee.getId());
		return "employeeDetailPage";
	}
	/**
	 * 返回公司列表
	 * @return
	 */
	public String companyQuery(){
		if(employee.getGroupId()!=null&&!employee.getGroupId().equals("")){
			//companyList=companyDao.getCompanyListByGroupId(employee.getGroupId());
		}
		return "companyListQueryJson";
	}
	/**
	 * 返回矿区列表
	 * @return
	 */
	public String collieryQuery(){
		if(employee.getCompanyId()!=null&&!employee.getCompanyId().equals("")){
			//collieryList=collieryDao.getCollieryListByCompanyId(employee.getCompanyId());
			
		}
		return "collieryListQueryJson";
	}
	/**
	 * 返回部门列表
	 * @return
	 */
	public String departmentQuery(){
		if(employee.getCollieryId()!=null&&!employee.getCollieryId().equals("")){
			//departmentList=departmentDao.getDepartmentListByCollieryId(employee.getCollieryId());
			
		}
		return "departmentListQueryJson";
	}
	
	public List<Employee> getEmployeeList() {
		return employeeList;
	}
	public void setEmployeeList(List<Employee> employeeList) {
		this.employeeList = employeeList;
	}
	public EmployeeDao getEmployeeDao() {
		return employeeDao;
	}
	@Resource
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
//	public DepartmentDao getDepartmentDao() {
//		return departmentDao;
//	}
//	@Resource
//	public void setDepartmentDao(DepartmentDao departmentDao) {
//		this.departmentDao = departmentDao;
//	}
//	public List<Department> getDepartmentList() {
//		return departmentList;
//	}
//	public void setDepartmentList(List<Department> departmentList) {
//		this.departmentList = departmentList;
//	}
//	public GroupDao getGroupDao() {
//		return groupDao;
//	}
//	@Resource
//	public void setGroupDao(GroupDao groupDao) {
//		this.groupDao = groupDao;
//	}
//	public CompanyDao getCompanyDao() {
//		return companyDao;
//	}
//	@Resource
//	public void setCompanyDao(CompanyDao companyDao) {
//		this.companyDao = companyDao;
//	}
//	public CollieryDao getCollieryDao() {
//		return collieryDao;
//	}
//	@Resource
//	public void setCollieryDao(CollieryDao collieryDao) {
//		this.collieryDao = collieryDao;
//	}
//	public List<Group> getGroupList() {
//		return groupList;
//	}
//	public void setGroupList(List<Group> groupList) {
//		this.groupList = groupList;
//	}
//	public List<Company> getCompanyList() {
//		return companyList;
//	}
//	public void setCompanyList(List<Company> companyList) {
//		this.companyList = companyList;
//	}
//	public List<Colliery> getCollieryList() {
//		return collieryList;
//	}
//	public void setCollieryList(List<Colliery> collieryList) {
//		this.collieryList = collieryList;
//	}
//	public List<Role> getRoleList() {
//		return roleList;
//	}
//	public void setRoleList(List<Role> roleList) {
//		this.roleList = roleList;
//	}
//	public RoleDao getRoleDao() {
//		return roleDao;
//	}
//	@Resource
//	public void setRoleDao(RoleDao roleDao) {
//		this.roleDao = roleDao;
//	}
//	

}
